home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / misc / emu / prlink_080b.lha / prlink-0.8.0b / src / prwfile.asm < prev    next >
Assembly Source File  |  1995-05-12  |  2KB  |  141 lines

  1.     processor 6502
  2.  
  3.     include "jmptab.inc"
  4.  
  5. #if target & pet4001
  6.     include "include/petram34.lib"
  7.     include "include/petrom4.lib"
  8. #endif
  9. #if target & pet3001
  10.     include "include/petram34.lib"
  11.     include "include/petrom3.lib"
  12. #endif
  13. #if target & (vic20 | c64 | c128)
  14.     include "include/cbmrom.lib"
  15. #endif
  16.  
  17.     seg code
  18.     org prutils
  19.  
  20. entry:
  21.     lda #0        ; send ack
  22.     jsr send_switch
  23.  
  24. loop:
  25.     ; write a file protocol:
  26.     ; C=             other computer
  27.     ; ack (00) ->
  28.     ;             <- <length>filename
  29.     ;             <- device #
  30.     ; st: ok (00) or error (!= 00) ->
  31.     ;             <- <length><chksum>datablock (255 bytes max)
  32.     ; ok (80) or again (81) or stop (82) ->
  33.     ; send same or next block, accordingly
  34.     ; last block has length 0 and no checksum or data.
  35.  
  36.     jsr receive_switch    ; get length of file name
  37.     sta fnlen
  38.     tax        ; test length
  39.     bne noexit
  40.     jmp exit    ; re-install server
  41. noexit: lda #<filebuf
  42.     sta fnadr
  43.     lda #>filebuf
  44.     sta fnadr+1
  45.     ldx #0        ; receive file name
  46.     stx status    ; clear ST
  47. fnam:
  48.     jsr receive    ; preserves x but sets y to 0.
  49.     sta filebuf,x
  50.     inx
  51.     cpx fnlen
  52.     bcc fnam
  53.  
  54.     jsr receive    ; receive device number
  55.     sta fa
  56.     lda #1        ; secondary addr always 1 for file write
  57.     sta sa
  58.  
  59. myfileno = 45
  60.     lda #myfileno    ; a hopefully unused file number
  61.     sta la
  62.     jsr open
  63.     lda status    ; now test for ourselves if we must continue
  64.     bne abort
  65.  
  66.     ldx #myfileno
  67.     jsr chkout
  68.     lda status
  69.     bne abort
  70.     jsr send_switch ; send 00 ok, going ahead code
  71.  
  72.         ; loop to receive blocks from the file
  73. nextblock:
  74.     jsr receive_switch
  75.     sta blklen
  76.     tax        ; set flags
  77.     beq eof     ; 0 means end of file
  78.     jsr receive    ; checksum
  79.     sta filebuf
  80.     ldx #0
  81.     stx chksum    ; clear checksum
  82. recv:
  83.     jsr receive
  84.     sta filebuf+1,x
  85.     clc        ; update checksum
  86.     adc chksum
  87.     sta chksum
  88.     inx
  89.     cpx blklen
  90.     bne recv
  91.  
  92.     cmp filebuf    ; check checksum
  93.     beq writeit
  94.     lda #$81    ; ask for a resend
  95.     jsr send_switch
  96.     sec
  97.     bcs nextblock
  98.  
  99. writeit:
  100.     ldx #0
  101. loop2:    bne loop    ; loop entry point (never branch in actual program)
  102. write:            ; write max 255 bytes from the file
  103.     lda status    ; test ST for EOI on previous byte
  104.     bne abort
  105.     jsr stop    ; test stop key
  106.     beq abort
  107.     lda filebuf+1,x
  108.     jsr chrout
  109.     inx
  110.     cpx blklen
  111.     bne write
  112.  
  113.     lda #$80    ; please send next block
  114.     jsr send_switch
  115.     sec
  116.     bcs nextblock
  117.  
  118. abort:
  119.     lda #$82
  120.     jsr send_switch ; send abort code
  121. eof:
  122.     jsr clrchn
  123.     lda #myfileno
  124.     jsr close
  125.     lda #1
  126.     bne loop2
  127.  
  128. endcode = .
  129.  
  130.     seg.u bss
  131.     org endcode
  132.  
  133. blklen:
  134.     ds.b 1        ; save block length
  135. chksum: ds.b 1        ; calculated checksum
  136. filebuf:
  137.     ds.b 256    ; checksum followed by 255 bytes of file data
  138.  
  139. endbss = .
  140.  
  141.